package com.lanou.hotel.controller;

import com.lanou.hotel.entity.User;
import com.lanou.hotel.service.IUserService;
import com.lanou.hotel.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author msy
 * @since 2023-10-17
 */
@RestController
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public ResultVO<Map<String, Object>> login(@RequestBody User user){
        return userService.login(user);
    }

    /**
     * 携带token
     * @param token
     * @return
     */
    @GetMapping("/info")
    public ResultVO<Map<String,Object>> info(String token){
        return userService.info(token);
    }

    /**
     * 注销
     * @param token
     * @return
     */
    @PostMapping("/logout")
    public ResultVO logout(@RequestHeader("X-Token") String token){
        return userService.logout(token);
    }
}
